package com.manage.project.biz.controller;

import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.framework.web.page.TableDataInfo;
import com.manage.project.biz.domain.BizGonglu;
import com.manage.project.biz.domain.BizJidiansheshiguzhangxuncha;
import com.manage.project.biz.domain.BizSuidao;
import com.manage.project.biz.domain.CivilEnginneeringAllMaintenance;
import com.manage.project.biz.service.IBizGongluService;
import com.manage.project.biz.service.IBizSuidaoService;
import com.manage.project.biz.service.ICivilEnginneeringAllMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
 * 养护方案计划Controller
 *
 * @author ycd
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/biz/allmaintenance")
public class CivilEnginneeringAllMaintenanceController extends BaseController
{
    @Autowired
    private ICivilEnginneeringAllMaintenanceService civilEnginneeringAllMaintenanceService;
//    @Autowired注解，可以对成员变量、方法和构造函数进行标注，来完成自动装配的工作；
    @Autowired
    private IBizGongluService roadInfoService;
    @Autowired
    private IBizSuidaoService iBizSuidaoService;

    /**
     * 查询养护方案计划列表
     */
    @PreAuthorize("@ss.hasPermi('biz:allmaintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(CivilEnginneeringAllMaintenance civilEnginneeringAllMaintenance)
    {
        startPage();
        List<CivilEnginneeringAllMaintenance> list = civilEnginneeringAllMaintenanceService.selectCivilEnginneeringAllMaintenanceList(civilEnginneeringAllMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出养护方案计划列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:allmaintenance:export')")
//    @Log(title = "养护方案计划", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, CivilEnginneeringAllMaintenance civilEnginneeringAllMaintenance) throws IOException {
//        List<CivilEnginneeringAllMaintenance> list = civilEnginneeringAllMaintenanceService.selectCivilEnginneeringAllMaintenanceList(civilEnginneeringAllMaintenance);
//        ExcelUtil<CivilEnginneeringAllMaintenance> util = new ExcelUtil<CivilEnginneeringAllMaintenance>(CivilEnginneeringAllMaintenance.class);
//        util.exportExcel(response, list, "养护方案计划数据");
//    }

    @Log(title = "养护方案计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CivilEnginneeringAllMaintenance civilEnginneeringAllMaintenance)
    {
        List<CivilEnginneeringAllMaintenance> list = civilEnginneeringAllMaintenanceService.selectCivilEnginneeringAllMaintenanceList(civilEnginneeringAllMaintenance);
        ExcelUtil<CivilEnginneeringAllMaintenance> util = new ExcelUtil<CivilEnginneeringAllMaintenance>(CivilEnginneeringAllMaintenance.class);
        return util.exportExcel(list, "养护方案计划数据");
    }
    /**
     * 获取养护方案计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:allmaintenance:query')")
    @GetMapping(value = "/{allMaintenanceId}")
    public AjaxResult getInfo(@PathVariable("allMaintenanceId") Long allMaintenanceId)
    {
        return AjaxResult.success(civilEnginneeringAllMaintenanceService.selectCivilEnginneeringAllMaintenanceByAllMaintenanceId(allMaintenanceId));
    }

    /**
     * 新增养护方案计划
     */
    @PreAuthorize("@ss.hasPermi('biz:allmaintenance:add')")
    @Log(title = "养护方案计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CivilEnginneeringAllMaintenance civilEnginneeringAllMaintenance)
    {
        String roadName=civilEnginneeringAllMaintenance.getRoadName();
        String tunnelName=civilEnginneeringAllMaintenance.getTunnelName();
        String tunnelId=civilEnginneeringAllMaintenance.getTunnelId();
        BizSuidao bizSuidao= iBizSuidaoService.getByTunnelNameIdAndRoadName(roadName,tunnelName,tunnelId);
        if(bizSuidao==null){
            return new AjaxResult().error("当前公路名称、隧道名称和隧道编码不对应，请核对后重新输入");
        }
        BizGonglu roadInfo=roadInfoService.checkByRoadName(roadName);
        if(roadInfo==null) {
            return new AjaxResult().error("当前道路不存在，请输入正确的道路名称");
        }else {
            return toAjax(civilEnginneeringAllMaintenanceService.insertCivilEnginneeringAllMaintenance(civilEnginneeringAllMaintenance));
        }
    }

    /**
     * 修改养护方案计划
     */
    @PreAuthorize("@ss.hasPermi('biz:allmaintenance:edit')")
    @Log(title = "养护方案计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CivilEnginneeringAllMaintenance civilEnginneeringAllMaintenance)
    {
        String roadName=civilEnginneeringAllMaintenance.getRoadName();
        String tunnelName=civilEnginneeringAllMaintenance.getTunnelName();
        String tunnelId=civilEnginneeringAllMaintenance.getTunnelId();
        BizSuidao bizSuidao= iBizSuidaoService.getByTunnelNameIdAndRoadName(roadName,tunnelName,tunnelId);
        if(bizSuidao==null){
            return new AjaxResult().error("当前公路名称、隧道名称和隧道编码不对应，请核对后重新输入");
        }
        BizGonglu roadInfo=roadInfoService.checkByRoadName(roadName);
        if(roadInfo==null) {
            return new AjaxResult().error("当前道路不存在，请输入正确的道路名称");
        }else {
            return toAjax(civilEnginneeringAllMaintenanceService.updateCivilEnginneeringAllMaintenance(civilEnginneeringAllMaintenance));
        }
    }

    /**
     * 删除养护方案计划
     */
    @PreAuthorize("@ss.hasPermi('biz:allmaintenance:remove')")
    @Log(title = "养护方案计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{allMaintenanceIds}")
    public AjaxResult remove(@PathVariable Long[] allMaintenanceIds)
    {
        return toAjax(civilEnginneeringAllMaintenanceService.deleteCivilEnginneeringAllMaintenanceByAllMaintenanceIds(allMaintenanceIds));
    }
}
